package com.cq.hd.member.api.vo;

import com.cq.hd.common.enums.biz.WithdrawalCheckItemTypeEnum;
import com.cq.hd.common.serialize.Decimal2Serializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author much
 * @since 2024/04/19 22:38
 */
@Data
public class WithdrawalCheckBillPreVo implements Serializable {
    private static final long serialVersionUID = 4984960823004815138L;

    @ApiModelProperty(value = "核算单id")
    private Long id;

    @ApiModelProperty(value = "甲方")
    private String partA;

    @ApiModelProperty(value = "乙方")
    private String partB;

    @ApiModelProperty(value = "服务项目")
    private String serviceItemDesc;

    @ApiModelProperty(value = "合作模式")
    private String collaborateModeText = "代理发放";

    @ApiModelProperty(value = "提现金额")
    @JsonSerialize(using = Decimal2Serializer.class)
    private BigDecimal withdrawalAmt;

    @ApiModelProperty(value = "结算金额")
    @JsonSerialize(using = Decimal2Serializer.class)
    private BigDecimal finalAmt;

    @ApiModelProperty(value = "核算类型：1-本金 2-补贴")
    private Integer checkType;

    @ApiModelProperty(value = "明细")
    private List<WithdrawalCheckItemVo> items;

    @ApiModelProperty(value = "结算账单明细（本金不展示）")
    public List<WithdrawalCheckItemVo> getBillItems() {
        if (checkType == 1) {
            return Collections.emptyList();
        }
        if (CollectionUtils.isEmpty(items)) {
            return Collections.emptyList();
        }
        return items.stream()
                .filter(e -> e.getType() == WithdrawalCheckItemTypeEnum.MERCHANT_SUBSIDY.getValue())
                .collect(Collectors.toList());
    }

    @ApiModelProperty(value = "费用明细")
    public List<WithdrawalCheckItemVo> getFeeItems() {
        List<Integer> feeTypes = Arrays.asList(
                WithdrawalCheckItemTypeEnum.FEE.getValue(), WithdrawalCheckItemTypeEnum.DEDUCTION.getValue(), WithdrawalCheckItemTypeEnum.ADD.getValue());
        if (CollectionUtils.isEmpty(items)) {
            return Collections.emptyList();
        }
        return items.stream()
                .filter(e -> feeTypes.contains(e.getType()))
                .collect(Collectors.toList());
    }

    @ApiModelProperty(value = "开票公司")
    public String getInvoiceCompany() {
        return "厦门火动通告科技有限公司";
    }

    @ApiModelProperty(value = "纳税人识别号")
    public String getTaxpayerIdNo() {
        return "91350200MAD1R4CD23";
    }

    @ApiModelProperty(value = "开户行")
    public String getBankName() {
        return "招商银行股份有限公司厦门软件园支行";
    }

    @ApiModelProperty(value = "银行账号")
    public String getBankCardNo() {
        return "592908801410401";
    }

    @ApiModelProperty(value = "公司地址")
    public String getCompanyAddress() {
        return "厦门火炬高新区软件园二期望海路10号503室I单元";
    }

    @ApiModelProperty(value = "电话")
    public String getMobile() {
        return "15905995368";
    }

    @ApiModelProperty(value = "开票内容")
    @JsonSerialize(using = Decimal2Serializer.class)
    public BigDecimal getInvoiceAmt() {
        return finalAmt;
    }

    @ApiModelProperty(value = "标题")
    public String getTitle() {
        if (checkType == 1) {
            return "火动通告订单本金结算单";
        } else {
            return "火动通告订单补贴结算单";
        }
    }

}
